// withdrawCash/pages/withdrawCash/withdrawCash.js
const service = require("./withdrawCashService.js");
const smallChangeService = require('../smallChange/smallChangeService.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pocketAccount: '0.00',// 我的零钱
    balance: '0.00',// 竞赛奖励
    goodTotal: 0, //宝贝数量
    isFocusUxuan: 1//是否关注趣闲吧公众号 0未关注 1关注
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: options.title
    });
  },
/**
 * 点击零钱提现
 */
  getCash:function(e){
    let that = this;
    // 获取是否关注趣闲吧公众号
    service.getFocusUxuan(function (res) {
      if (res) {
        that.setData({
          isFocusUxuan: res,
        });
        if (res == 1) {
          wx.navigateTo({
            url: '../smallChange/smallChange',
          })
        }
      } else {
      that.setData({
        isFocusUxuan: 0,
      });
    }

    });
  },
  /**
   * 点击竞赛奖励提现
   */
  battleCash:function(e){
    let that = this;
    // 获取是否关注趣闲吧公众号
    service.getFocusUxuan(function (res) {
      if (res){
        that.setData({
          isFocusUxuan: res,
        });
        if (res == 1) {
          var url = "https://card-h5.zuanliantech.com/box/#/prizeList?token=" + getApp().globalData.accessToken
          wx.navigateTo({
            url: "/pages/web/web?url=" + encodeURIComponent(url) + "&title=" + "提现",
          })
        }
      } else {
        that.setData({
          isFocusUxuan: 0,
        });
      }
    });
  },
  /**
   * 点击零钱明细
   */
  looseMoneyDetailClick: function (e) {
      wx.navigateTo({
        url: '/withdrawCash/pages/moneyDetail/moneyDetail?moneyType=0&title=' + '零钱明细',
      });
  },

  /**
   * 点击奖励明细
   */
  prizeDetailClick: function (e) {
    wx.navigateTo({
      url: '/withdrawCash/pages/moneyDetail/moneyDetail?moneyType=1&title=' + '奖励明细',
    });
  },

  /**
   * 点击我领到的宝贝
   */
  myReceivedGoodsClick: function (e) {
    console.log('aaaa');
    wx.redirectTo({
      url: '/mineSubs/pages/getBaby/getBaby?type=1',
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // 提现帮助view
    this.withdrawCashHelp = this.selectComponent("#withdrawCashHelp");
    this.withdrawCashHelp.requestRule()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    // 零钱总额
    smallChangeService.getCashListData(function (res){
      that.setData({
        pocketAccount: res.pocketAccount,
        goodTotal: res.goodTotal
      });
    });
    // 竞赛奖励
    service.getCompetitionBalanceDetail(function (res) {
      if (res.balance) {
        that.setData({
          balance: res.balance
        });
      }
    });
  },

  /**
   * 提现帮助
   */
  help: function () {
    this.withdrawCashHelp.show()
  },

  /**
   * 提交表单
   */
  submitForm: function (e) {
    // 获取表单id
    let formId = e.detail.formId;
    getApp().saveUserFormId(formId, 23);
  },
})